package com.teziyou.commodity.logic;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.teziyou.commodity.enumtype.EnableEnum;
import com.teziyou.commodity.service.TicketService;
import com.teziyou.commodity.util.ConvertUtil;
import com.teziyou.commodity.util.Lists;

@SuppressWarnings({"rawtypes","unchecked"})
@Service
public class TicketLogic extends TicketService {
	
	public List listTickets(Map<String, String> paramMap) {
		List ticketList = super.findTicketsByPage(paramMap);
		Iterator iter = ticketList.iterator();
		while(iter.hasNext()) {
			Map ticket = (Map)iter.next();
			long sceneId = ConvertUtil.toInt(ticket.get("scenic_id"));
			Map scene = super.findSceneById(sceneId);
			ticket.put("scene_name", scene.get("name"));
			ticket.put("isOK_display", EnableEnum.getEnumByCode(ConvertUtil.toInt(ticket.get("isOK"))).getDesc());
		}
		return ticketList;
	}
	
	public List loadTickets(String ids) {
		List list = Lists.newArrayList();
		if(StringUtils.isNotBlank(ids)) {
			String[] idStrs = ids.split(",");
			for(String id:idStrs) {
				if(StringUtils.isNotBlank(id)) {
					Map ticket = super.findTicketById(Long.parseLong(id));
					long sceneId = ConvertUtil.toInt(ticket.get("scenic_id"));
					Map scene = super.findSceneById(sceneId);
					ticket.put("scene_name", scene.get("name"));
					ticket.put("isOK_display", EnableEnum.getEnumByCode(ConvertUtil.toInt(ticket.get("isOK"))).getDesc());
					list.add(ticket);
				}
			}
		}
		return list;
	}

}
